package com.zcn.io.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zcn.io.common.pojo.CommonResult;
import com.zcn.io.common.vo.OrderMainForTrusteeshipVo;
import com.zcn.io.web.api.dto.MaintenanceDto;
import com.zcn.io.web.api.entity.Maintenance;
import com.zcn.io.web.api.query.MaintenanceQuery;
import com.zcn.io.web.api.vo.MaintenanceVo;
import com.zcn.io.web.service.MaintenanceService;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @desc: 维护信息
 * @author: 202438 邱建伟
 * @date: 2025/4/20 14:45
 */
@RestController
@AllArgsConstructor
@RequestMapping("/maintenance")
public class MaintenanceController {

    private final MaintenanceService maintainableService;

    @GetMapping("/list")
    public CommonResult<Page<MaintenanceVo>> list(Page<MaintenanceVo> page,  MaintenanceQuery query){
        maintainableService.list(page, query);
        return CommonResult.success(page);
    }

    @PostMapping("/addMaintenance")
    public CommonResult addMaintenance(@RequestBody Maintenance maintenance) {
        maintainableService.addMaintenance(maintenance);
        return CommonResult.success("新增成功");
    }

    @PostMapping("/updateMaintenance")
    public CommonResult updateMaintenance(@RequestBody MaintenanceDto maintenance) {
        maintainableService.updateMaintenance(maintenance);
        return CommonResult.success("修改成功");
    }

    /**
     * @desc: 获取托管详情信息
     * @author 202438 邱建伟
     * @date 2025/5/2 17:38
     */
    @GetMapping("/getTrusteeshipDetailById")
    public CommonResult<OrderMainForTrusteeshipVo> getTrusteeshipDetailById(String dtlId) {
        return CommonResult.success(maintainableService.getTrusteeshipDetailById(dtlId));
    }

//    @PreAuthorize("hasAuthority('super_man')")
    @DeleteMapping("/deleteById")
    @PreAuthorize("hasAuthority('super_man')")
    public CommonResult<String> deleteById(String id) {
        maintainableService.deleteById(id);
        return CommonResult.success("删除成功");
    }

}
